#include "BlockOuter.h"
#include "ILevel.h"
#include "Record.h"
#include "Common.h"

namespace WLog
{
    BlockOuter::BlockOuter(ostream &out)
        : RegularOuter(out)
    {

    }

    BlockOuter::~BlockOuter()
    {

    }

    bool BlockOuter::outRecord(Record *pRecord, ILevel *pLevel)
    {
#define STRING_TABLE_LINE "+--------------------------------------------------+"
#define STRING_TABLE_START "+ "
#define STRING_TABLE_END " +"
#define STRING_TABLE_SPLIT " | "
        if (!pLevel->callBack_BeforeOut(pRecord, this))
        {
            return false;
        }
        
        if (pLevel->bOutName())
        {
            out(STRING_TABLE_LINE); outendl(); 
            out(STRING_TABLE_START);
            m_out.width(20);m_out.setf(std::ios::left);
            out(pLevel->getName());
        }
        if (pLevel->bOutTime())
        {
            out(STRING_TABLE_SPLIT);
            out(pRecord->m_strTime);
            outendl();
        }
        
        if (pLevel->bOutFuncName())
        {
            out(STRING_TABLE_START);
            m_out.width(20);
            out(pRecord->m_strFuncName);
        }
        if (pLevel->bOutLineNo())
        {
            out(STRING_TABLE_SPLIT);
            out("(line): ");
            out(l2str(pRecord->m_nLine));
            outendl();
        }

        if (pLevel->bOutFileName())
        {
            out(STRING_TABLE_START);            
            out(pRecord->m_strFileName);
            outendl();
        }

        if (pLevel->bOutLineNo())
        {
            out(STRING_TABLE_START);
            out("(message): ");
        }

        out(pRecord->m_strMsg);

        if (pLevel->bNewLine())
        {       
            outendl();
            out(STRING_TABLE_LINE);outendl();
            outendl();
        }

        return pLevel->callBack_AfterOut(pRecord, this);
    }
}
